package PTA_05_29;

import java.text.DecimalFormat;
import java.util.*;

abstract class Person {
    private String name;
    private String cha;//定义了输入对象的类型，'s'或'e'
    private int age;
    private boolean gender;

    public Person(String cha, String name, int age, boolean gender) {
        this.cha = cha;
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getCha(){ return cha; }

    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }

    @Override
    public boolean equals(Object obj) {
        Person p1 = (Person) obj;
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (p1.name==null||this.name==null)
            return false;
        return this.getName().equals(p1.getName()) &&
                this.getAge() == p1.getAge() &&
                this.isGender() == p1.isGender();
    }

    @Override
    public String toString() {
        return getName() + "-" + getAge() + "-" + isGender();
    }

    @Override
    public int hashCode()
    {
        return Objects.hash(name);
    }
}

class Student extends Person {
    private String stuNo;
    private String clazz;

    public Student(String cha, String name, int age, boolean gender, String stuNo, String clazz) {
        super(cha, name, age, gender);
        this.stuNo = stuNo;
        this.clazz = clazz;
    }

    public Student() {
    }

    public String getStuNo() {
        return stuNo;
    }

    public void setStuNo(String stuNo) {
        this.stuNo = stuNo;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    @Override
    public boolean equals(Object obj) {
        if (super.equals(obj)) {
            Student s1 = (Student) obj;
            if (this == obj)
                return true;
            if(!super.equals(obj))
                return false;
            return this.getClazz().equals(s1.getClazz()) &&
                    this.getStuNo().equals(s1.getStuNo());
        }else {
            return false;
        }
    }

    @Override
    public String toString() {
        return "Student:" + super.toString() +
                "-" + getStuNo() + "-" + getAge();
    }
}

class Company
{
    private String name;

    public Company() {
    }

    public Company(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj)
            return true;
        if(!(obj instanceof Company))
            return false;
        Company c1 = (Company) obj;
        return this.getName().equals(c1.getName());
    }

    @Override
    public String toString() {
        return name;
    }
}

class Employee1 extends Person
{
    private Company company;
    private double salary;

    public Employee1(String cha, String name, int age, boolean gender, Company company, double salary) {
        super(cha, name, age, gender);
        this.company = company;
        this.salary = salary;
    }

    public Employee1() {
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public boolean equals(Object obj) {
        if(super.equals(obj))
        {
            if(this == obj)
                return true;
            if(!(obj instanceof Employee1))
                return false;
            Employee1 e1 = (Employee1) obj;
            Double newSalary1 = Double.valueOf(new DecimalFormat("#.#").format(e1.salary));
            Double newSalary2 = Double.valueOf(new DecimalFormat("#.#").format(this.salary));
            //比较salary属性时，使用DecimalFormat df = new DecimalFormat("#.#")，保留1位小数
            return Double.compare(newSalary1, newSalary2) == 0 &&
                    Objects.equals(this.getCompany(), e1.getCompany());
        }
        return false;
    }

    @Override
    public String toString() {
        return "Employee:"+super.toString()+'-'+company+'-'+salary;
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), company, salary);
    }
}
public class Main5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String next = sc.next();
        List<Person> personList = new ArrayList<>();
        List<Student> stuList = new ArrayList<>();
        List<Employee1> empList = new ArrayList<>();
        while (next.equals("s") || next.equals("e")) {
            if (next.equals("s")) {//如果为‘s’则新建Studen对象
                Student student = new Student(next, sc.next(), sc.nextInt(), sc.nextBoolean(), sc.next(), sc.next());
                personList.add(student);//将student对象加入到personList中
                next = sc.next();
            } else {//如果为‘e’则新建Employee对象
                String name = sc.next();
                int age = sc.nextInt();
                Boolean gender = sc.nextBoolean();
                double salary = sc.nextDouble();
                Company company = new Company(sc.next());
                Employee1 employee = new Employee1(next, name, age, gender, company, salary);
                personList.add(employee);//将employee对象加入到personList中
                next = sc.next();
            }
        }
        personList.sort(Comparator.comparing(Person::getName).thenComparingInt(Person::getAge));

        for (int i = 0; i < personList.size(); i++) {
            System.out.println(personList.get(i).toString());
            if (personList.get(i).getCha().equals("s")) {
                //如果是"s"则分配到stuList中
                int flag = 0;
                for (int j = 0; j < stuList.size(); j++) {//判断是否有两个内容相同的对象
                    if (personList.get(i).equals(stuList.get(j))) {
                        flag = 1;
                        break;
                    }
                    if (flag == 0) {
                        stuList.add((Student) personList.get(i));
                    }
                }
            } else {
                //否则到emplist中
                int flag = 0;
                for (int j = 0; j < empList.size(); j++) {
                    if (personList.get(i).equals(empList.get(j))) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {
                    empList.add((Employee1) personList.get(i));
                }
            }
        }
        String nextStep = sc.next();
        if (nextStep.equals("exit") || nextStep.equals("return")) {//判断下一步是否要继续进行
            return;
        } else {//输出stuList与empList中的内容
            System.out.println("stuList");
            for (int i = 0; i < stuList.size(); i++) {
                System.out.println(stuList.get(i).toString());
            }
            System.out.println("empList");
            for (int i = 0; i < empList.size(); i++) {
                System.out.println(empList.get(i).toString());
            }
        }
    }
}